package com.orgname.glvone.glvtwo.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.orgname.glvone.glvtwo.common.exception.BusinessException;
import com.orgname.glvone.glvtwo.common.exception.ParamValidException;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class Response extends BaseResponse {

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public static Response failedResponse() {
        return failedResponse(FAILED_MESSAGE);
    }

    public static Response failedResponse(BusinessException businessException) {
        Response resp = new Response();
        resp.setCode(businessException.getCode());
        resp.setMessage(businessException.getMessage());
        return resp;
    }

    public static Response failedResponse(ParamValidException paramValidException) {
        Response resp = new Response();
        resp.setCode(paramValidException.getCode());
        resp.setMessage(paramValidException.getMessage());
        return resp;
    }

    public static Response failedResponse(String message) {
        Response resp = new Response();
        resp.setCode(FAILED);
        resp.setMessage(message);
        return resp;
    }

    public static Response failedResponse(Integer code, String message) {
        Response resp = new Response();
        resp.setCode(code);
        resp.setMessage(message);
        return resp;
    }

    public static Response succeededResponse(Object data) {
        Response resp = new Response();
        resp.setCode(SUCCEEDED);
        resp.setData(data);
        return resp;
    }

    public static Response succeededResponse() {
        Response resp = new Response();
        resp.setCode(SUCCEEDED);
        return resp;
    }
}
